import jsonpath


class GetKeyword:

    @staticmethod
    def get_keyword(source_data,keyword):
        return jsonpath.jsonpath(source_data,f'$..{keyword}')[0]

    def get_keywords(source_data,keywords):
        return jsonpath.jsonpath(source_data,f'$..{keywords}')

if __name__ == '__main__':
    test_data={'status_code': 200, 'headers': {'Vary': 'Origin, Access-Control-Request-Method, '
                                                       'Access-Control-Request-Headers', 'X-Content-Type-Options':
        'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, '
                                                                         'no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0',
                                               'X-Frame-Options': 'DENY', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Date': 'Mon, '
                                                                                                                                                      '17 Oct 2022 03:27:07 GMT', 'Keep-Alive': 'timeout=60', 'Connection': 'keep-alive'},
               'body': {'code': 200, 'message': '操作成功', 'data': {'tokenHead': 'Bearer ', 'token': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImNyZWF0ZWQiOjE2NjU5NzcyMjc2MjksImV4cCI6MTY2NjU4MjAyN30.q2PTtc_C7KOkQlRBustbXCAOXyGXJxIZTnM8vQnRCVZsI4nC_kdmBYHP3B07WwJRmY5OvY_uffZZG142musMrw'}}, 'response_time': 120}

    # print(GetKeyword.get_keyword(test_data, 'token'))
    # print(GetKeyword.get_keyword(test_data, 'tokenHead')[0])